// pages/order/order-detail/order-detail.js
//pages/order/order-detail/order-detail?orderId=xx

var httpUtil = require('../../../utils/httpUtil.js')
var uiUtil = require('../../../utils/uiUtil.js')
var util = require('../../../utils/util.js')
var emptyUtil = require('../../templates/empty/empty.js')
var that
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderDetail: null,

    orderStatusImg: null, //订单状态图片

    emptyParam: {
      emptyStatus: 0
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    that = this
    var orderId = options.orderId
    if (orderId) {
      this.requestOrderDetail(orderId)
    } else {
      emptyUtil.showFailView("获取订单信息失败")
    }
  },
  onShareAppMessage: function(res) {
    return util.handleShareApp()
  },
  /**
   * 客服点击
   */
  onContactClick() {
    var hotlineNo = this.data.orderDetail.hotlineNo
    if (hotlineNo) {
      wx.makePhoneCall({
        phoneNumber: hotlineNo,
      })
    }
  },

  /**
   * 获取订单详情
   */
  requestOrderDetail(orderId) {
    uiUtil.showLoading("请稍候..")
    httpUtil.PostRequest("order_detail", {
      orderId: orderId
    }, {
      success(res) {
        that.setData({
          orderDetail: res
        })
        that.dealOrderStatusImg(res)
      },
      fail(code, res) {
        var text = emptyUtil.getErrText(code, res, "获取订单信息失败")
        emptyUtil.showFailView(text)
      },
      complete() {
        uiUtil.hideLoading()
      }
    })
  },

  /**
   * 处理订单状态图片
   */
  dealOrderStatusImg(orderDetail) {
    var orderStatus = orderDetail.orderStatus
    var orderChildStatus = orderDetail.orderChildStatus
    var result;
    if ('noPay' == orderChildStatus) {
      result = '/resources/image/order_detail_status_noconfirm.png'
    } else if ('overflow' == orderChildStatus) {
      result = '/resources/image/order_detail_status_overflow.png'
    } else if ('noSend' == orderStatus) {
      result = '/resources/image/order_detail_status_nosend.png'
    } else if ('noTake' == orderStatus) {
      result = '/resources/image/order_detail_status_notake.png'
    } else if ('success' == orderStatus) {
      result = '/resources/image/order_detail_status_success.png'
    } else if ('fail' == orderStatus) {
      result = '/resources/image/order_detail_status_fail.png'
    } else if ('cancel' == orderStatus) {
      result = '/resources/image/order_detail_status_cancel.png'
    } else {
      result = '/resources/image/order_detail_status_noconfirm.png'
    }
    this.setData({
      orderStatusImg: result
    })
  },


})